#!/usr/bin/env python

"""
Sheet URL
https://spreadsheets.google.com/a/bike7now.co.cc/ccc?key=t56719I3djHxs16KXlKMtDQ&hl=zh_TW
Sheet View
https://spreadsheets.google.com/a/bike7now.co.cc/lv?key=0Ava5-tZ5ZxAKdDU2NzE5STNkakh4czE2S1hsS010RFE&f=0
https://spreadsheets.google.com/lv?key=0Ava5-tZ5ZxAKdDU2NzE5STNkakh4czE2S1hsS010RFE&f=0

"""

import time
import gdata.spreadsheet.service
import getpass, string

email = 'ziyu4huang@bike7now.co.cc'
aemail = raw_input("Enter Your mail account:")
if aemail and len(aemail) > 0:
  email = aemail

print 'use mail account %s' % (email)

password = getpass.getpass("password for Your Google Account:")
weight = '180'
# Find this value in the url with 'key=XXX' and copy XXX below
spreadsheet_key = 't56719I3djHxs16KXlKMtDQ'
# All spreadsheets have worksheets. I think worksheet #1 by default always
# has a value of 'od6'
worksheet_id = 'od6'

spr_client = gdata.spreadsheet.service.SpreadsheetsService()
spr_client.email = email
spr_client.password = password
spr_client.source = 'Example Spreadsheet Writing Application'
spr_client.ProgrammaticLogin()

# Prepare the dictionary to write
dict = {}
dict['date'] = time.strftime('%Y/%m/%d')
dict['time'] = time.strftime('%H:%M:%S')
dict['weight'] = weight
print dict

start_time = time.time()

if True:
  for i in range(1, 200):
    spr_client.InsertRow(dict, spreadsheet_key, worksheet_id)
end_time = time.time()

print "%f seconds" % (end_time - start_time)

entry = spr_client.InsertRow(dict, spreadsheet_key, worksheet_id)
if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
  print "Insert row succeeded."
else:
  print "Insert row failed."

